package com.xgst.land.activity.check

import android.view.View
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.widget.TextView
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xgst.land.R
import com.xgst.land.bean.LandUIDBean


/**
 * 白色：后台告诉我，这个位置没有试管
 * 蓝色：后台告诉我，这个位置有试管
 * 绿色：通过扫描，发现了这个试管
 * 红色：通过扫描发现这个试管不是这个样本盒中的
 * 黄色：通过扫描，发现这个试管是借用状态
 */
class PDScanLandAdapter:BaseQuickAdapter<LandUIDBean,BaseViewHolder>(R.layout.item_scall_layout) {
    override fun convert(holder: BaseViewHolder, item: LandUIDBean) {
        holder.setText(R.id.tvName,"${item.originalLocation}")
        val tvName = holder.getView<TextView>(R.id.tvName)
        if(item.type == 2){
            //借用
            tvName.setTextColor(context.getColor(R.color.white))
            tvName.setBackgroundResource(R.drawable.shape_scan_item_jieyong_bg)
        }else if(item.query){
            //查询
            tvName.setTextColor(context.getColor(R.color.white))
            if(item.originalUid  != item.newUid && item.newUid != null && item.originalUid != null){
                tvName.setBackgroundResource(R.drawable.shape_scan_item_red_biankuang)
            }else{
                tvName.setBackgroundResource(R.drawable.shape_scan_item_query_bg)
            }
            flicker(holder.itemView)
        }else{
            if(item.originalUid == null && item.newUid == null){
                //孔位没有试管  白底黑字
                tvName.setTextColor(context.getColor(R.color.black))
                tvName.setBackgroundResource(R.drawable.shape_scan_item_white_bg)
            }else if(item.originalUid == null && item.newUid != null){
                //原本是空的，现在有试管了，多余的
                tvName.setTextColor(context.getColor(R.color.white))
                tvName.setBackgroundResource(R.drawable.shape_scan_item_red_bg)
            }else if(item.originalUid != null && item.newUid == null){
                //原本有，没扫描到
                if(item.type == 0){
                    //还没有开始扫描，所以蓝色图标占位
                    tvName.setTextColor(context.getColor(R.color.black))
                    tvName.setBackgroundResource(R.drawable.shape_scan_item_blue_bg)
                }else if(item.type == 1){
                    //开始扫描了
                    tvName.setTextColor(context.getColor(R.color.white))
                    tvName.setBackgroundResource(R.drawable.shape_scan_item_red_bg)
                }
            }else if(item.originalUid  == item.newUid && item.newUid != null){
                //原本有，扫描到了
                tvName.setTextColor(context.getColor(R.color.white))
                tvName.setBackgroundResource(R.drawable.shape_scan_item_green_bg)
            }else if(item.originalUid  != item.newUid && item.newUid != null && item.originalUid != null){
                //位置错误了
                tvName.setTextColor(context.getColor(R.color.white))
                tvName.setBackgroundResource(R.drawable.shape_scan_item_red_bg)
            }
        }
    }

    fun flicker(view: View) {
        val alphaAnimation = AlphaAnimation(0f, 1.0f)
        alphaAnimation.duration = 800
        alphaAnimation.interpolator = LinearInterpolator()
        alphaAnimation.repeatCount = Animation.INFINITE
        alphaAnimation.repeatMode = Animation.REVERSE
        view.startAnimation(alphaAnimation)
    }

    fun clearAnimation(view: View) {
        view.clearAnimation()
    }
}
